﻿using PreeRegisterDAL;
using PreeRegisterModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace PreeRegisterBLL
{
    public class LocalPacsBLL
    {
        public static LocalPacsModel.PacsPatInfoListResponseModel GetLabReportList(LocalPacsModel.PacsPatInfoListByTimeRequestModel request)
        {
            LocalPacsModel.PacsPatInfoListResponseModel ReportListResponseModel = new LocalPacsModel.PacsPatInfoListResponseModel();
            try
            {
                //查询检验报告列表
                //LocalPacsDAL localPacsDAL = new LocalPacsDAL();
                DataSet ds = null;
                if (request.adnum!=null && !request.adnum.Equals(""))
                {
                     ds = LocalPacsDAL.GetLabReportListByAdnum(request.starttime, request.endtime,request.adnum);
                }
                else
                {
                     ds = LocalPacsDAL.GetLabReportListByTime(request.starttime, request.endtime);
                }

                if (ds == null)
                {
                    ReportListResponseModel.code = "0";
                    ReportListResponseModel.msg = "获取影像列表错误";
                    return ReportListResponseModel;
                }

                //获取检验报告列表
                List<LocalPacsModel.PacsPatInfoModel> list = new List<LocalPacsModel.PacsPatInfoModel>();

                foreach (DataRow items in ds.Tables[0].Rows)
                {
                    LocalPacsModel.PacsPatInfoModel model = new LocalPacsModel.PacsPatInfoModel();
                    model.unitId = items["unitId"].ToString();
                    model.applyno = items["xeguid"].ToString();
                    model.studyid = items["studyid"].ToString();
                    model.patientid = items["patientidnumber"].ToString();
                    model.telephone = items["telnumber"].ToString();
                    model.devicetypename = items["devicetypename"].ToString();
                    model.devicename = items["devicename"].ToString();
                    model.studystatus = items["studystatus"].ToString();
                    model.name = items["patientname"].ToString();
                    model.patientage = items["patientage"].ToString();
                    model.patientageunit = items["patientageunit"].ToString();
                    model.patientename = items["patientename"].ToString();
                    model.sex = items["patientsex"].ToString();
                    model.studyfilenum = items["imagecount"].ToString();
                    model.registertime = items["registertime"].ToString();
                    model.studytime = items["studytime"].ToString();
                    model.studyplace = items["studydescribe"].ToString();
                    model.patientoutpatientid = items["patientoutpatientid"].ToString();
                    model.patientinpatientid = items["patientinpatientid"].ToString();
                    model.patienttypename = items["patienttypename"].ToString();
                    model.departmentid = items["departmentid"].ToString();
                    model.isavailable = items["isavailable"].ToString();
                    model.deptid = items["ApplyDeptID"].ToString();         //申请科室id
                    model.deptname = items["ApplyDeptName"].ToString();  //申请科室名称
                    model.ApplyDocID = items["ApplyDocID"].ToString();     //申请医生id
                    model.ApplyDocName = items["ApplyDocName"].ToString();//申请医生姓名
                    model.clinicdiag = items["diagnose"].ToString();   //报告诊断 必填
                    model.advice = items["advice"].ToString();   //报告建议 必填
                    model.DESCRIBE = items["DESCRIBE"].ToString();    //报告描述 必填
                    model.ReportTime = items["ReportTime"].ToString();
                    model.FinallyEditTime = items["FinallyEditTime"].ToString(); //报告最后修改时间 必填
                    model.doctorname1 = items["doctorname1"].ToString();     //该报告的一线医生 必填
                    model.doctorname2 = items["doctorname2"].ToString();     //该报告的二线医生 必填
                    model.doctorname3 = items["doctorname3"].ToString();  //该报告的三线医生 必填-没有可为空值
                    model.tempsavestate = items["tempsavestate"].ToString(); //暂存标记（1为暂存|0为正常）	必填
                    model.ifmasculine = items["ifmasculine"].ToString(); //是否阳性，0：未确定，1：阴性，2：阳性 必填
                    list.Add(model);
                }


                if (list.Count>0)
                {
                    ReportListResponseModel.code = "1";
                    ReportListResponseModel.msg = "获取影像列表成功";
                    ReportListResponseModel.result = list;
                }
                else
                {
                    ReportListResponseModel.code = "0";
                    ReportListResponseModel.msg = "没有找到匹配信息";
                    ReportListResponseModel.result = list;
                }

                
                //返回
                return ReportListResponseModel;
            }
            catch (Exception err)
            {
                ReportListResponseModel.code = "0";
                ReportListResponseModel.msg = "获取影像列表异常";
                throw;
            }
        }
    }
}
